<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.keywords" placeholder="提现帐号、提现名称" clearable></el-input>
      </el-form-item>
      <el-form-item label="打款方式">
		<el-select v-model="dataForm.accType" placeholder="打款方式">
          <el-option label="全部" value="" ></el-option>
		  <el-option label="商家端银行卡" value="0" ></el-option>
		  <el-option label="用户端微信" value="1" ></el-option>
		  <el-option label="公司手动打款" value="2" ></el-option>
          <el-option label="商户支付宝提现" value="3" ></el-option>
		</el-select>
	  </el-form-item>
      <el-form-item label="来源">
		<el-select v-model="dataForm.withSrc" placeholder="来源">
          <el-option label="全部" value="" ></el-option>
		  <el-option label="安卓" value="0" ></el-option>
		  <el-option label="苹果" value="1" ></el-option>
		  <el-option label="小程序" value="2" ></el-option>
          <el-option label="后台" value="3" ></el-option>
		</el-select>
	  </el-form-item>
      <el-form-item label="起始时间">
		<el-date-picker
          v-model="dataForm.startTime"
          type="datetime"
          value-format = "yyyy-MM-dd HH:mm:ss"
          placeholder="起始时间">
		</el-date-picker>
	  </el-form-item>
	  <el-form-item label="结束时间">
		<el-date-picker
          v-model="dataForm.endTime"
          type="datetime"
          value-format = "yyyy-MM-dd HH:mm:ss"
          placeholder="结束时间">
		</el-date-picker>
	  </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button @click="
          dataForm.accType = ''
          dataForm.cashStatus = ''
          dataForm.status = ''
          dataForm.keywords = ''
          getDataList()">重置</el-button>
        <el-button icon="el-icon-download" type="primary" @click="excel()">导出</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column type="expand">
        <template slot-scope="props">
        <el-form label-position="left" inline class="demo-table-expand">
          <el-table :data="props.row.list">
            <el-table-column>
              <template slot-scope="scope">
                <span>单号：{{scope.row.payNo}}</span>
                <span style="margin-left:60px">买家账号：{{scope.row.payUserName}}</span>
                <span style="margin-left:60px">买家名称：{{scope.row.payTrueName}}</span>
                <span style="margin-left:60px">商家账号：{{scope.row.storeUserName}}</span>
                <span style="margin-left:60px">商家名称：{{scope.row.storeTrueName}}</span>
                <span style="margin-left:60px">提现金额：{{scope.row.money}}</span>
                <span style="margin-left:60px">时间：{{scope.row.createTime}}</span>
                <!-- <el-button type="text" size="small" @click="addOrUpdateHandle1(scope.row.id)" style="float:right">订单详情</el-button> -->
              </template>
            </el-table-column>
          </el-table>
        </el-form>
      </template>
      </el-table-column>
      <!-- <el-table-column
        prop="orderNo"
        header-align="center"
        align="center"
        label="订单编号">
      </el-table-column> -->
      <el-table-column
        prop="accType"
        header-align="center"
        align="center"
        label="帐号类型">
        <template slot-scope="scope">
          <span v-if="scope.row.accType === 0">商家端银行卡</span>
          <span v-if="scope.row.accType === 1">用户端微信</span>
          <span v-if="scope.row.accType === 2">公司手动打款</span>
          <span v-if="scope.row.accType === 3">商户支付宝提现</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="accountNo"
        header-align="center"
        align="center"
        label="提现帐号">
      </el-table-column>
      <el-table-column
        prop="cashSatus"
        header-align="center"
        align="center"
        label="提现状态">
        <template slot-scope="scope">
            <span v-if="scope.row.cashSatus === 0">提现失败</span>
            <span v-if="scope.row.cashSatus === 1">提现成功</span>
            <span v-if="scope.row.cashSatus === 2">提现中</span>
            <span v-if="scope.row.cashSatus === 3">待审核</span>
            <span v-if="scope.row.cashSatus === 4">已审核</span>
            <span v-if="scope.row.cashSatus === 5">审核不通过</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        label="时间">
      </el-table-column>
      <el-table-column
        prop="money"
        header-align="center"
        align="center"
        label="提现总金额">
      </el-table-column>
      <el-table-column
        prop="withUserName"
        header-align="center"
        align="center"
        label="提现名称">
      </el-table-column>
      <el-table-column
        prop="withUserType"
        header-align="center"
        align="center"
        label="提现用户类型">
        <template slot-scope="scope">
            <p v-if="scope.row.withUserType == 1"> 区域运营商</p>
            <p v-else-if ="scope.row.withUserType == 2">普通联盟店</p>
            <p v-else-if ="scope.row.withUserType == 3">消费者</p>
            <p v-else-if ="scope.row.withUserType == 4">VIP会员</p>
            <p v-else-if ="scope.row.withUserType == 5">中级版联盟店</p>
            <p v-else-if ="scope.row.withUserType == 6">高级版联盟店</p>
            <p v-else-if ="scope.row.withUserType == 7">城市合伙人</p>
            <p v-else-if ="scope.row.withUserType == 8">城市合伙人联盟店</p>
          </template>
      </el-table-column>
      <el-table-column
        prop="withSrc"
        header-align="center"
        align="center"
        label="提现来源">
        <template slot-scope="scope">
            <span v-if="scope.row.withSrc === 0">安卓</span>
            <span v-if="scope.row.withSrc === 1">苹果</span>
            <span v-if="scope.row.withSrc === 2">小程序</span>
            <span v-if="scope.row.withSrc === 3">后台</span>
        </template>
      </el-table-column> 
      <!-- <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id,scope.row.orderType,scope.row.payNo)">订单详情</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <weekcashwithdrawal v-if="addOrUpdateVisible" ref="weekRef" @refreshDataList="getDataList"></weekcashwithdrawal>
    <month v-if="addOrUpdateVisible" ref="monthRef" @refreshDataList="getDataList"></month>
  </div>
</template>

<script>
  import AddOrUpdate from './businesswithrecord-add-or-update'
  import weekcashwithdrawal from './weekcashwithdrawal'
  import month from './monthcashwithdrawal'
  export default {
    data () {
      return {
        dataForm: {
          keywords: '',
          accType: '',
          withSrc: '',
          startTime: '',
          endTime: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate,
      weekcashwithdrawal,
      month
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/cashAudit/queryDiscountRecordList'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'keywords': this.dataForm.keywords,
            'accType': this.dataForm.accType,
            'withSrc': this.dataForm.withSrc,
            'startTime': this.dataForm.startTime,
            'endTime': this.dataForm.endTimer
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.data.list
            this.totalPage = data.data.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 周提现
      weekcashwithdrawal () {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.weekRef.init(1)
        })
      },
      // 月提现
      month () {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.monthRef.init(2)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.withrecordid
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/generator/businesswithrecord/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      excel () {
        window.location.href = this.$http.adornUrl(`/cashAudit/cashWithdrawalRecordExcel?token=${this.$cookie.get('token')}&endTime=${this.dataForm.endTime}&startTime=${this.dataForm.startTime}&userName=${this.dataForm.keywords}`)
      }
    }
  }
</script>
